/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package classes;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.logging.Level;
import java.util.logging.Logger;
import rad.Java.Common.Class.DefaultList;
import rad.Java.Common.Class.IList;
import rad.Java.Common.DB.GenerateSql;

/**
 *
 * @author rogerio
 */
public class tecnicos extends DefaultList implements IList{

    private tecnico t;
    public tecnicos()
    {
        t = new tecnico();
        _gsql = new GenerateSql();
        _gsql.setTable("tecnico");
    }

    public tecnico get(int index)
    {
        return (tecnico) _items.get(index);
    }

    public boolean fillList() {
        _gsql.prepare();
        _gsql.setCommandType(GenerateSql.CommandType.CMD_SELECT);
        _gsql.setValue("","*");
        _gsql.setConditionalWhere("tecnico_enable = 'true'");
        try {
            return mountList();
        } catch (SQLException ex) {
            Logger.getLogger(tecnicos.class.getName()).log(Level.SEVERE, null, ex);
            return false;
        }
    }

    public boolean fillList(String sql) throws SQLException
    {
        _gsql.prepare();
        _gsql.setCommandType(GenerateSql.CommandType.CMD_SELECT);
        _gsql.setValue("","*");
        _gsql.setConditionalWhere(sql);
        _gsql.setConditionalWhere("tecnico_enable = 'true'");
        _gsql.setAditionalWhere("ORDER BY tecnico_name");
    
        return mountList();
    }

    private boolean mountList() throws SQLException
    {
        ResultSet rs;
        if (!_gsql.execute(false))
            return false;
        clear();

        while(_gsql.next())
        {
            tecnico c = new tecnico();
            c.get(_gsql.getResultSet());
            _items.add(c);
        }
        return true;
    }
}
